#include <iostream>
#include <stdlib.h>

using namespace std;

int **matrixmul(int a, int b, int c, int d, int e, int f,int g, int h )
{

	int** first = new int*[2];
for(int i = 0; i < 2; ++i)
    first[i] = new int[2];

int** second = new int*[2];
for(int j = 0; j < 2; ++j)
    second[j] = new int[2];

int** result = new int*[2];
for(int k = 0; k < 2; ++k)
    result[k] = new int[2];
	int c1, k1, d1;
	int sum=0;
	first[0][0]=a;
	first[0][1]=b;
	first[1][0]=c;
	first[1][1]=d;

	second[0][0]=e;
	second[0][1]=f;
	second[1][0]=g;
	second[1][1]=h;
		
    for ( c1 = 0 ; c1 <2; c1++ )
    {
      for ( d1 = 0 ; d1 < 2 ; d1++ )
      {
        for ( k1 = 0 ; k1 < 2 ; k1++ )
        {
          sum = sum + first[c1][k1]*second[k1][d1];
        }
 
        result[c1][d1] = sum;
        sum = 0;
      }
    }
 
    cout<<"Product of entered matrices:-"<<endl;
 
    for ( c1 = 0 ; c1 < 2 ; c1++ )
    {
      for ( d1 = 0 ; d1 < 2 ; d1++ )
        cout<<result[c1][d1]<<"   ";
 
      cout<<endl;
    }
  
for(int i = 0; i < 2; ++i) {
    delete [] first[i];
}
delete [] first;

for(int i = 0; i < 2; ++i) {
    delete [] second[i];
}
delete [] second;



  return result;
}


  

int** addmat(int a, int b, int c, int d, int e, int f,int g, int h)
{
	int** first = new int*[2];
for(int i = 0; i < 2; ++i)
    first[i] = new int[2];

int** second = new int*[2];
for(int j = 0; j < 2; ++j)
    second[j] = new int[2];

int** result = new int*[2];
for(int k = 0; k < 2; ++k)
    result[k] = new int[2];
	int c1, k1, d1;
	
	first[0][0]=a;
	first[0][1]=b;
	first[1][0]=c;
	first[1][1]=d;

	second[0][0]=e;
	second[0][1]=f;
	second[1][0]=g;
	second[1][1]=h;

	for ( c1 = 0 ; c1 < 2 ; c1++ )
      for ( d1 = 0 ; d1 < 2 ; d1++ )
         result[c1][d1] = first[c1][d1] + second[c1][d1];

	cout<<"Addition of entered matrices:-"<<endl;
 
    for ( c1 = 0 ; c1 < 2 ; c1++ )
    {
      for ( d1 = 0 ; d1 < 2 ; d1++ )
        cout<<result[c1][d1]<<"   ";
 
      cout<<endl;
    }
for(int i = 0; i < 2; ++i) {
    delete [] first[i];
}
delete [] first;

for(int i = 0; i < 2; ++i) {
    delete [] second[i];
}
delete [] second;

	return result;
}

int** submat(int a, int b, int c, int d, int e, int f,int g, int h)
{
int** first = new int*[2];
for(int i = 0; i < 2; ++i)
    first[i] = new int[2];

int** second = new int*[2];
for(int j = 0; j < 2; ++j)
    second[j] = new int[2];

int** result = new int*[2];
for(int k = 0; k < 2; ++k)
    result[k] = new int[2];
	int c1, k1, d1;
	
	first[0][0]=a;
	first[0][1]=b;
	first[1][0]=c;
	first[1][1]=d;

	second[0][0]=e;
	second[0][1]=f;
	second[1][0]=g;
	second[1][1]=h;

	for ( c1 = 0 ; c1 < 2 ; c1++ )
      for ( d1 = 0 ; d1 < 2 ; d1++ )
         result[c1][d1] = first[c1][d1] - second[c1][d1];

	cout<<"Subtraction of entered matrices:-"<<endl;
 
    for ( c1 = 0 ; c1 < 2 ; c1++ )
    {
      for ( d1 = 0 ; d1 < 2 ; d1++ )
        cout<<result[c1][d1]<<"   ";
 
      cout<<endl;
    }

for(int i = 0; i < 2; ++i) {
    delete [] first[i];
}
delete [] first;

for(int i = 0; i < 2; ++i) {
    delete [] second[i];
}
delete [] second;
return result;
}

int main()
{
  
 
  matrixmul(2, 2, 2, 2,2,2,2,2);
	//submat(3, 3, 3,3, 2, 2, 2, 2);
  
}
